package com.example.text.cyclone



import android.os.Build
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import com.example.text.ui.mall.random.RandomPicProvider

object RichTextHelper {
    val MOCK_CONTENT =
        "<p>这里是非常详细的活动介绍1</p><img src='${RandomPicProvider.pic()}'/>" +
                "<p>这里是非常详细的活动介绍2</p><img src='${RandomPicProvider.pic()}'/>" +
                "<p>这里是非常详细的活动介绍3</p><img src='${RandomPicProvider.pic()}'/>" +
                "<p>这里是非常详细的活动介绍4</p><img src='${RandomPicProvider.pic()}'/>" +
                "<p>这里是非常详细的活动介绍5</p><img src='${RandomPicProvider.pic()}'/>" +
                "<p>这里是非常详细的活动介绍6</p><img src='${RandomPicProvider.pic()}'/>" +
                "<p>这里是非常详细的活动介绍7</p><img src='${RandomPicProvider.pic()}'/>" +
                "<p>这里是非常详细的活动介绍8</p><img src='${RandomPicProvider.pic()}'/>"


    fun displayRichText(webView: WebView, content: String) {
        WebViewUtils.initWebViewSettings(webView)
        webView.loadDataWithBaseURL(null, getHtmlData(content), "text/html", "utf-8", null)
    }

    private fun getHtmlData(bodyHTML: String): String {
        val head = ("<head>"
                + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> "
                + "<style>img{max-width: 100%; width:100%; height:auto;}*{margin:0px;}</style>"
                + "</head>")
        return "<html>$head<body>$bodyHTML</body></html>"
    }

}